import {HTTP} from '../utils/http-p.js';

class KeywordModel extends HTTP{
    key = "q";
    maxLength = 12;
    getHistory(){
        const words = wx.getStorageSync(this.key);
        if(!words){
            return [];
        }
        return words;
    }

    getHot(){
        return this.request({
            url:"book/hot_keyword"
        });
    }

    addToHistory(keyword){
        let words = this.getHistory();
        const has = words.includes(keyword);
        if(!has){
            //如果超出一定大小，
            if(words.length>this.maxLength){
                words.pop();
            }
            words.unshift(keyword);
            wx.setStorageSync(this.key,words);
        }
    }
}

export {KeywordModel}